package com.tangpian.framework.web.controller.account;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tangpian.framework.entity.User;
import com.tangpian.framework.service.user.AccountService;

@Controller
@RequestMapping(value = "/register")
public class AccountController {
	
	@Autowired
	private AccountService accountService;
	
	@RequestMapping(method=RequestMethod.GET)
	public String showRegisterForm(ModelMap model) {
		model.put("user", new User());
		return "user/register";
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public String create(@Valid @ModelAttribute User user, BindingResult result) {
		accountService.register(user);
		return "redirect:/";
	}

}
